package com.vsoft.sms_cm;

import java.io.DataOutputStream;
import java.lang.Thread;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.log4j.Logger;

import com.vsoft.framework.core.BaseException;
import com.vsoft.framework.core.BusiObj;
import com.vsoft.framework.core.Configuration;
import com.vsoft.framework.core.db.DBGadgets;
import com.vsoft.framework.core.db.DBTrans;
import com.vsoft.framework.core.esb.ServiceBus;
import com.vsoft.framework.core.util.BOHelper;
import com.vsoft.framework.core.util.LogCollect;
import com.vsoft.framework.core.util.XMLUtil;
import com.vsoft.framework.server.servlet.SessionData;
import com.vsoft.framework.server.servlet.HttpUtil;
import com.vsoft.anti_fra.*;

public class TestCacheModeMultiTheads {

	private static Logger vLogger = Logger.getLogger(TestCacheModeMultiTheads.class);
	private static String vName = TestCacheModeMultiTheads.class.getName();
	private SessionData vSD = null;
	private String vDebugHome = "";
	private BusiObj				vInBO		=  new BusiObj();
	public static Connection Servconn = null;
	
	
	public static void main(String[] args)  {
	
		try{

			vLogger.info("---------------InitSystem-------------");
			Configuration.InitSystem();
			vLogger.info("---------------generate test data-------------");
			Connection conn = DBTrans.getConnection();
			Servconn	=	conn;
			BusiObj bo=new BusiObj() ;
			TableCacheServer.init(conn);
			
			bo.setString("order_num", "05662020861");// 05503084030（两个模板：企业编码10009，100009）
			//05512690095  短信模板未审核    05662023940  cdr_type=3
			//05512683516  短信模板无群组
			//05513659663
			bo.setString("mobile_num", "13973284157");//白名单15305669789  普通电话：18955179099
			int cnt=0;
			for(int i =0;i<=20;i++)
			{
				Thread t = new MyThread();
				MyThread.init(conn);
				t.start();
/*				for (int j=1;j<=3;j++)
				{
					cnt++;
					vLogger.info("===========test   i="+i+"       j="+j +"      cnt="+cnt);
					bo.setString("order_num", "05662020861");// 05503084030（两个模板：企业编码10009，100009）
					bo.setString("mobile_num", "15305669020");//白名单15305669789  普通电话：18955179099
					bo.setString("cdr_type", String.valueOf(j));
					bo.setConnection(conn);
					bo=TableCacheServer.getTempleForSend(bo);
					//vLogger.info("返回数据是:\n\n\n\n" + BOHelper.boToXML(bo));
				}*/
				
			}

			Customer customer = new Customer();

/*			StaticBO.setString("cdr_type", "4");
			StaticBO.setString("order_num", "05503084030");// 05512681039 白名单：888
			StaticBO.setString("mobile_num", "18955179099");//
			StaticBO	=	customer.getCalledSMSTemple(StaticBO);*/
			vLogger.info("返回数据是:\n\n\n\n" + BOHelper.boToXML(bo));
		        //DBGadgets.check(conn);
			conn.rollback();
			//conn.commit();
			//conn.close();
			//vLogger.info("返回数据是:\n\n\n\n" + BOHelper.boToXML(retBo));


		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
		catch(BaseException e)
		{
			e.printStackTrace();
			vLogger.error(e.ErrMethod);
			vLogger.error(e.SysMsg);
		}
			vLogger.info("---------------Game Over-------------");
	}	

		

	private int  init()
	{
		int iRet = 0;
		vSD = new  SessionData();
		vSD.vRoleCode = new String[] {"1"};
		vSD.vStaffCode = "1";
		vSD.vStaffNo = "0001";
		vSD.vStaffName = "test";
		
	
		vDebugHome = System.getProperty("DEBUG_HOME");
		if (vDebugHome == null)
		{
			iRet = -1;
			vLogger.error("需要设置DEBUG_HOME环境变量来指定debug 文件所在的目录");
		}
		return iRet;
		
	}

	
}
class MyThread extends Thread
{
	private static Logger vLogger = Logger.getLogger(TestCacheModeMultiTheads.class);
	private static String vName = TestCacheModeMultiTheads.class.getName();
	public int x = 0;
	public static Connection conn = null;
	public static void init(Connection Servconn )
	{
		conn =Servconn;
	}
	public void run()
	{
		for (int j=1;j<=3;j++)
		{
			
			BusiObj bo=new BusiObj() ;
			bo.setString("order_num", "05662020861");// 05503084030（两个模板：企业编码10009，100009）
			bo.setString("mobile_num", "15305669020");//白名单15305669789  普通电话：18955179099
			bo.setString("cdr_type", String.valueOf(j));
			bo.setConnection(conn);
			try {
				bo=TableCacheServer.getTempleForSend(bo);
				//vLogger.info("返回数据是:\n\n\n\n" + BOHelper.boToXML(bo));
			} catch (BaseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println(++x);
		}
	}
}